<script>
jQuery(function() {
  jQuery("form input").keypress(function (e) {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
      return false;
    } else {
      return true;
    }
  });
});

var members = [];

function remove(id) {
  var confirmed = confirm("Are you sure to remove this user from proyect?");
  if (confirmed) {
    members.splice(members.indexOf(id), 1); // elimina el valor ID del array members
    jQuery('#member_'+id).fadeOut("slow", function() {
      jQuery('#member_'+id).remove();
    });
  }
  return false;
}

jQuery(document).ready( function(){
  {foreach from=$project->user item="member"}
  members.push({$member->id});
  {/foreach}

  /*
   * AUTOCOMPLETE DEVELOPER
   */
  jQuery("#developer_autocomplete").autocomplete("{base_url()}users/get_ajax/", {
     type: "POST",
     selectFirst: false
  });
  jQuery("#developer_autocomplete").setOptions({
    extraParams: {
      members: members
    }
  });

  jQuery("#developer_autocomplete").result(function(event, data, formatted) {
    if (data) {
      jQuery("#developers").append(
        '<div id="member_'+data[1]+'" class="pwcore-project-edit-member developer">'+
        '<input class="input" type="hidden" name="developers[]" value="'+data[1]+'" />'+
        '<span class="remove-member"><a onclick="return remove('+data[1]+');" href="#" title="Remove Member">X</a> </span>'+
        '<label>'+data[0]+'</label>'+
        '</div>'
      );
      members.push(data[1]);
      jQuery(this).flushCache();
      jQuery(this).val("");
    }
  });

});
</script>